﻿
//********************************************************************************//
//创建日期：<创建日期，2016-4-14>
//页面创建：<孙雪婷，sunxueting@shanghai3h.com>
//后台逻辑：
//功能说明：非税接口
//********************************************************************************//
using BLL;
using BLL.Access;
using Entity;
using System;
using System.Data;
using System.Web;
using Web.Class;

namespace Web.Pages.YongShui.ZhangWuGL
{
    public partial class FeiShuiJK : BasePage
    {
        #region 属性
        /// <summary>
        /// 保存结果集
        /// </summary>
        private DataTable dtSourceWSC
        {
            get
            {
                return ViewState["dtSourceWSC"] as DataTable;
            }
            set
            {
                ViewState["dtSourceWSC"] = value;
            }
        }

        /// <summary>
        /// 保存结果集
        /// </summary>
        private DataTable dtSourceYSC
        {
            get
            {
                return ViewState["dtSourceYSC"] as DataTable;
            }
            set
            {
                ViewState["dtSourceYSC"] = value;
            }
        }

        #endregion

        #region 变量
        SpHelper _sphelper = new SpHelper();
        #endregion

        #region 事件
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitData();
            }
            this.ScriptManager1.RegisterPostBackControl(btnShengChengWJ);
            gvWeiShangC.DataSource = dtSourceWSC;
            gvWeiShangC.DataBind();

            gvYiShangC.DataSource = dtSourceYSC;
            gvYiShangC.DataBind();
        }

        protected void btnRefrush_Click(object sender, EventArgs e)
        {
            QueryData();
        }

        /// <summary>
        /// 生成数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnShengChengSJ_Click(object sender, EventArgs e)
        {
            int zwny = Convert.ToInt32(txtZhangWuNY.Text.Trim());
            int userid = LoginInfo.CurrentUser.UserID;
            string strErrMsg = string.Empty;
            if (zwny > 0)
            {
                DataSet ds = _sphelper.P_YSZW_FSJKSCSJ(zwny,userid, out strErrMsg);
                PageTools.AlertMsg(this, strErrMsg);
                QueryData();
            }
            else
            {
                PageTools.AlertMsg(this, "请输入账务年月！");
            }
        }
        /// <summary>
        /// 生成文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnShengChengWJ_Click(object sender, EventArgs e)
        {
            if (dtSourceWSC.Rows.Count > 0)
            {
                int wjbh = Convert.ToInt32(this.gvWeiShangC.GetRowValues(this.gvWeiShangC.FocusedRowIndex, "I_ID"));
                string wjm = this.gvWeiShangC.GetRowValues(this.gvWeiShangC.FocusedRowIndex, "S_WENJIANM").ToString() + ".txt";
                DataTable dt = _sphelper.P_YSZW_FSSCWJ_QXWJ(2, wjbh).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    //生成文件
                    PageTools.CreateTxt(dt, wjm);
                    QueryData();
                }
                else
                {
                    PageTools.AlertMsg(this, "请选择需要生成的文件");
                }
            }

            else
            {
                PageTools.AlertMsg(this, "没有需要生成的文件");
            }

        }

        /// <summary>
        /// 生产文件---暂时使用此按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //protected void Button1_Click(object sender, EventArgs e)
        //{
        //    ShengChengWJ();
        //    //PageTools.ExportToExcel("财税接口.txt", "fjsldfjklj福建省的路费进口量", "");
        //}
        
        /// <summary>
        /// 取消文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuXiaoWJ_Click(object sender, EventArgs e)
        {
            int wjbh = Convert.ToInt32(this.gvYiShangC.GetRowValues(this.gvYiShangC.FocusedRowIndex, "I_ID"));
            DataTable dt = _sphelper.P_YSZW_FSSCWJ_QXWJ(1, wjbh).Tables[0];
            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0][0].ToString() == "0")
                {
                    PageTools.AlertMsg(this, "取消成功！");
                }
            }
            QueryData();
        }
        #endregion

        #region 方法

        private void InitData()
        {
            int zwym = BusinessTool.GetZWYM();
            txtZhangWuNY.Text = zwym.ToString();
            QueryData();
        }

        private void QueryData()
        {
            dtSourceWSC = _sphelper.P_YSZW_GETFSSJ(0).Tables[0];
            if (dtSourceWSC != null)
            {
                gvWeiShangC.DataSource = dtSourceWSC;
                gvWeiShangC.DataBind();
            }
            dtSourceYSC = _sphelper.P_YSZW_GETFSSJ(1).Tables[0];
            if (dtSourceYSC != null)
            {
                gvYiShangC.DataSource = dtSourceYSC;
                gvYiShangC.DataBind();
            }
        }

        #endregion
    }
}